/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FriendProfile.java
 *
 * Created on Apr 20, 2012, 10:31:58 AM
 */

import java.sql.ResultSet;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Blob;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.imageio.stream.ImageInputStream;
import sun.misc.BASE64Decoder;

/**
 *
 * @author jacobsm
 */
public class FriendProfile extends javax.swing.JPanel {

    Controller controller;
    DatabaseConnection dbConnect;
    int visibility;

    /** Creates new form FriendProfile */
    public FriendProfile(Controller controller, DatabaseConnection db) {
        initComponents();
        this.controller = controller;
        this.dbConnect = db;
    }

    /**
       Changes the profiles information given a username to look up
    **/
    public void getInformation(String username) {
        String selectQuery = String.format(
                "SELECT email, description, visibility FROM user WHERE username = '%s'",
                username
        );
        ResultSet user = dbConnect.executeQuery(selectQuery);
        this.setUsername(username);
        try {
            user.next();
            String email = user.getString(1);
            String description = user.getString(2);
            visibility = user.getInt(3);
            this.setEmail(email);
            this.setDescription(description);
        }
        catch (SQLException e) {
            System.err.println("");
        }
    }

    public boolean checkIfFriends(){ 
        String friendsQuery1 = "SELECT user1, user2 FROM friends WHERE user1 = '"
                   + controller.username + "' AND user2 = '" + usernameLabel.getText() + "';";
        String friendsQuery2 = "SELECT user1, user2 FROM friends WHERE user1 = '"
                   + usernameLabel.getText() + "' AND user2 = '" + controller.username + "';";

        ResultSet friends1 = dbConnect.executeQuery(friendsQuery1);
        ResultSet friends2 = dbConnect.executeQuery(friendsQuery2);

        if(friends1 == null)
            return false;
        if(friends2 == null)
            return false;

        return true;
    }

    public void setFields(){
        String getStatsQuery = String.format(
                "SELECT * FROM user_stats WHERE username='%s'",
                usernameLabel.getText()
        );

        dbConnect.connect();
        ResultSet stats = dbConnect.executeQuery(getStatsQuery);

        if (stats != null) {
            try {
                stats.next();
                numWinsLabel.setText(Integer.toString(stats.getInt(2)));
                numLossesLabel.setText(Integer.toString(stats.getInt(3)));
            } catch (SQLException e) {
                // TODO Handle failure.
                System.err.println("Failed to get user's stats.");
            } finally {
                dbConnect.closeConnection();
            }
        }
        else {
            numWinsLabel.setText("0");
            numLossesLabel.setText("0");
        }
    }

    public void updateStats() {
        String friend;

        //Based on visibility permissions
        switch (visibility){
            //All users
            case (2):
                setFields();
                break;
                
            //Friends only
            case (1):
                if(checkIfFriends()){
                    setFields();
                    break;
                }

            //No one
            case (0):
                numWinsLabel.setText("Permission needed");
                numLossesLabel.setText("Permission needed");
                break;
        }
    }

    public void updateGamesList() {
        if (!controller.username.equals(usernameLabel.getText())) {
            return;
        }

        userGameList.setListData(new Object[]{});

        String getGamesQuery = String.format(
                "SELECT * FROM game_state WHERE user1='%s' OR user2='%s'",
                controller.username, controller.username
        );
        dbConnect.connect();
        ResultSet games = dbConnect.executeQuery(getGamesQuery);

        if (games != null) try {
            String gameItemFmt = "User: %s   State: %s";
            ArrayList<String> gameItems = new ArrayList<String>();

            while (games.next()) {
                String gameState = null;
                String gameOpponent = null;

                if (usernameLabel.getText().equals(games.getString(1))) {
                    gameState = games.getInt(4) == 1 ? games.getString(3) : "wait";
                    gameOpponent = games.getString(2);
                }
                else {
                    gameState = games.getInt(4) == 2 ? games.getString(3) : "wait";
                    gameOpponent = games.getString(1);
                }

                gameItems.add(String.format(gameItemFmt, gameOpponent, gameState));
            }

            userGameList.setListData(gameItems.toArray());
        }
        catch (SQLException e) {
            // TODO Handle failure.
            System.err.println("Failed to query user's game list: " + e.getLocalizedMessage());
        }
        finally {
            dbConnect.closeConnection();
        }
    }

    /**
        Sets the username label to be correct
    **/
    public void setUsername(String username) {
        this.usernameLabel.setText(username);
    }

    /**
        Sets the email label to be correct
    **/
    public void setEmail(String email) {
        this.userEmailLabel.setText(email);
    }

    /**
        Sets the email label to be correct
    **/
    public void setDescription(String description) {
        this.userDescriptionTextPane.setText(description);
    }

    public void setProfilePicture(BufferedImage pic) {
        if (pic != null) {
            Image scaledImage = pic.getScaledInstance(
                    200, 200, Image.SCALE_DEFAULT);

            avatarLabel.setIcon(new javax.swing.ImageIcon(scaledImage));
        }
    }

    public void setProfilePicture(Blob pic) throws SQLException{
        if(pic != null){
            try {
                BufferedImage image = ImageIO.read(pic.getBinaryStream());
                Image scaledImage = image.getScaledInstance(
                        200, 200, Image.SCALE_DEFAULT
                );

                avatarLabel.setIcon(new javax.swing.ImageIcon(scaledImage));

            } catch (IOException ex) {
                System.out.println("Profile picture could not be read.");
            }
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        bannerLabel = new javax.swing.JLabel();
        userInfoPanel = new javax.swing.JPanel();
        avatarLabel = new javax.swing.JLabel();
        usernameLabel = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        userEmailLabel = new javax.swing.JLabel();
        numWinsLabel = new javax.swing.JLabel();
        numLossesLabel = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        userGameList = new javax.swing.JList();
        jLabel8 = new javax.swing.JLabel();
        removeFromFriendsButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        userDescriptionTextPane = new javax.swing.JTextPane();
        playButton = new javax.swing.JButton();
        myProfileButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        jPanel1.setBackground(new java.awt.Color(0, 102, 153));

        bannerLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        bannerLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/draw-something-logo.jpg"))); // NOI18N
        bannerLabel.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        avatarLabel.setBackground(new java.awt.Color(255, 255, 255));
        avatarLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/empty_profile_picture.gif"))); // NOI18N
        avatarLabel.setText("jLabel1");
        avatarLabel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        usernameLabel.setFont(new java.awt.Font("Tahoma", 1, 18));
        usernameLabel.setForeground(new java.awt.Color(0, 0, 255));
        usernameLabel.setText("Username");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel3.setText("Wins:");

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel4.setText("Losses:");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel5.setText("Email:");

        userEmailLabel.setFont(new java.awt.Font("Tahoma", 1, 12));
        userEmailLabel.setText("userEmail");

        numWinsLabel.setFont(new java.awt.Font("Tahoma", 1, 12));
        numWinsLabel.setText("numWins");

        numLossesLabel.setFont(new java.awt.Font("Tahoma", 1, 12));
        numLossesLabel.setText("numLosses");

        javax.swing.GroupLayout userInfoPanelLayout = new javax.swing.GroupLayout(userInfoPanel);
        userInfoPanel.setLayout(userInfoPanelLayout);
        userInfoPanelLayout.setHorizontalGroup(
            userInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(userInfoPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(avatarLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(userInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(userInfoPanelLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(userInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(userInfoPanelLayout.createSequentialGroup()
                                .addGroup(userInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel3))
                                .addGap(18, 18, 18))
                            .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE))
                        .addGroup(userInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(userEmailLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)
                            .addComponent(numWinsLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(numLossesLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(49, 49, 49))
                    .addGroup(userInfoPanelLayout.createSequentialGroup()
                        .addGap(71, 71, 71)
                        .addComponent(usernameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );
        userInfoPanelLayout.setVerticalGroup(
            userInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(userInfoPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(userInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(userInfoPanelLayout.createSequentialGroup()
                        .addComponent(usernameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(userInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(userEmailLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(userInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(numWinsLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(userInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(numLossesLabel)))
                    .addComponent(avatarLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 21, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 445, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 9, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 445, Short.MAX_VALUE)
        );

        userGameList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Game 1", "Game 2", "Game 3", "Game 4", "Game 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane2.setViewportView(userGameList);

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel8.setForeground(new java.awt.Color(255, 255, 255));
        jLabel8.setText(" Current Games");

        removeFromFriendsButton.setText("Remove friend");
        removeFromFriendsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeFromFriendsButtonActionPerformed(evt);
            }
        });

        userDescriptionTextPane.setText("User description here.");
        jScrollPane1.setViewportView(userDescriptionTextPane);

        playButton.setText("Play");
        playButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                playButtonActionPerformed(evt);
            }
        });

        myProfileButton.setText("Back To Profile");
        myProfileButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                myProfileButtonActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("    User Options");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(userInfoPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(4, 4, 4)
                                        .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, 162, Short.MAX_VALUE))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(6, 6, 6)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(removeFromFriendsButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)))))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 657, Short.MAX_VALUE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(bannerLabel)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(myProfileButton, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(playButton, javax.swing.GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(41, 41, 41)))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(myProfileButton, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(playButton, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(bannerLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 109, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(removeFromFriendsButton, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(userInfoPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 215, Short.MAX_VALUE)))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 719, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(0, 0, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 0, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 571, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(0, 0, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 0, Short.MAX_VALUE)))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void removeFromFriendsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeFromFriendsButtonActionPerformed
        String removeQuery1 = "DELETE FROM friends WHERE user1 = '" + controller.username +
                "' AND user2 = '" + usernameLabel.getText() +"';";
        String removeQuery2 = "DELETE FROM friends WHERE user1 = '" + usernameLabel.getText() +
                "' AND user2 = '" + controller.username +"';";

        dbConnect.executeUpdate(removeQuery1);
        dbConnect.executeUpdate(removeQuery2);
    }//GEN-LAST:event_removeFromFriendsButtonActionPerformed

    private void myProfileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_myProfileButtonActionPerformed
        this.controller.openProfile();
    }//GEN-LAST:event_myProfileButtonActionPerformed

    private void playButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_playButtonActionPerformed
        this.controller.openGame(usernameLabel.getText());
    }//GEN-LAST:event_playButtonActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel avatarLabel;
    private javax.swing.JLabel bannerLabel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton myProfileButton;
    private javax.swing.JLabel numLossesLabel;
    private javax.swing.JLabel numWinsLabel;
    private javax.swing.JButton playButton;
    private javax.swing.JButton removeFromFriendsButton;
    private javax.swing.JTextPane userDescriptionTextPane;
    private javax.swing.JLabel userEmailLabel;
    private javax.swing.JList userGameList;
    private javax.swing.JPanel userInfoPanel;
    private javax.swing.JLabel usernameLabel;
    // End of variables declaration//GEN-END:variables

}
